package java学习;

import java学习.算法.测试.arr;

import java.util.Arrays;
import java.util.Scanner;

/**
 * **************
 * 项目名称: 蓝桥杯-Java学习 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦Lenovo <br/>
 * 创建时间: 2022/9/24 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
public class 秋招360 {
    /**
     * 2 2
     * 2 1
     * 1 1
     * 3 4
     * 1 2 3
     * 3 2 1
     * 3 2 5
     * 5 6 7
     * @param args
     */
    public static void main(String[] args) {
        float c = 3.4f+1f;
        Scanner sc = new Scanner(System.in);
        int a, b;
        a = sc.nextInt();// M
        b = sc.nextInt();// N
//        System.out.println(a);
//        System.out.println(b);
        sc.nextInt();
        int[][] arr  =new int[a][b];
        int [] a1 = new int[]{1,2,3};
        int sum = 0;
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    arr[i][j] = sc.nextInt();
                    sum+=arr[i][j];
                }
        }
//        System.out.println(Arrays.deepToString(arr));
        System.out.println(func(arr, sum * 6));
    }

    public static int func(int[][] arr,int sum) {
        int zinner = 0,xinner=0,yinner=0;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr[0].length-1; j++) {
                while (arr[i][j]>=1){
                    zinner+=2;
                    if (arr[i+1][j] == arr[i][j]){
                        yinner+=2;
                    }
                    if (arr[i][j+1] == arr[i][j]){
                        xinner+=2;
                    }
                    arr[i][j]--;
                }

            }
        }
        return sum-zinner-xinner-yinner;
    }
}
